
import json
from bs4 import BeautifulSoup

import requests


class page_number(object):

    def headers(self):
        self.header = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0'}
        self.url = 'https://jobs.51job.com/beijing/'
        self.html = requests.get(self.url, headers=self.header, timeout=2000)
        self.soup = BeautifulSoup(self.html.text.encode(
            'iso-8859-1').decode('gbk'), 'html.parser')
        print(type(self.url))


    def page(self):
        self.number = 0
        self.result = []
        for self.x in range(1,11):
            self.one = {}
            self.one[self.x] =self.url+ 'p'+ str(self.x)
            self.result.append((self.one))
            self.number += 1
        print(self.number)
        print(self.result)

    def write_data(self):
        with open('page.json','w',encoding='utf-8') as self.file:
            self.file.write(json.dumps(self.result,indent=2,ensure_ascii=False))
            self.file.close()

        # self.a=1
        # print(self.a)





if __name__ == '__main__':
    p = page_number()
    p.headers()
    p.page()
    p.write_data()
